package com.sundi.ecgeneralize.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundi.eccommon.utils.ExcelBean;
import com.sundi.eccommon.utils.ExcelUtils;
import com.sundi.ecgeneralize.dto.AdDto;
import com.sundi.ecgeneralize.dto.CouponDto;
import com.sundi.ecgeneralize.entity.EcAd;
import com.sundi.ecgeneralize.entity.EcCoupon;
import com.sundi.ecgeneralize.mapper.EcAdMapper;
import com.sundi.ecgeneralize.service.IEcAdService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 广告表 服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-03-12
 */
@Service
public class EcAdServiceImpl extends ServiceImpl<EcAdMapper, EcAd> implements IEcAdService {

    @Override
    public List<EcAd> selectAdList(AdDto adDto) {
        return this.baseMapper.selectAdList(adDto);
    }

    @Override
    public void updAndDel(Integer id) {
        this.baseMapper.updAndDel(id);
    }

    @Override
    public EcAd getAd(Integer id) {
        return this.baseMapper.getAd(id);
    }

    @Override
    public XSSFWorkbook downLoadAdExcel(AdDto adDto) throws Exception {
        PageHelper.startPage(adDto.getPageNum(),adDto.getPageSize());
        List<EcAd> ecAds = this.selectAdList(adDto);
        PageInfo<EcAd> info = new PageInfo<>(ecAds);

        Map<Integer,List<ExcelBean>> map = new HashMap<Integer,List<ExcelBean>>();
        List<ExcelBean> excelBeans = new ArrayList<>();
        excelBeans.add(new ExcelBean("广告ID","id",0));
        excelBeans.add(new ExcelBean("广告标题","name",0));
        excelBeans.add(new ExcelBean("广告内容","content",0));
        excelBeans.add(new ExcelBean("广告图片","url",0));
        excelBeans.add(new ExcelBean("广告位置","position",0));
        excelBeans.add(new ExcelBean("活动链接","link",0));
        excelBeans.add(new ExcelBean("是否启动","enabled",0));

        map.put(0,excelBeans);

        return ExcelUtils.createExcelFile(EcAd.class,info.getList(),map,"广告管理列表");
    }


}
